<?php
/*
 * Created on Feb 5, 2009
 * @author: ANH
 * @PARAM rtype is rootType: example: caves is type then attraction is rtype
 * @filesource: modules/place/controllers/PlaceController.php
 */

class Place_DevelController extends Clu_Controller_Action_Hvn
{
	protected $mode;
	public function init()
	{
		//require_once  (APP_PATH.'/modules/article/Model/Article.php');
		//require_once  (APP_PATH.'/modules/category/Model/Category.php');
		//require_once  (APP_PATH.'/modules/comment/Model/Comment.php');
		//require_once  (APP_PATH.'/modules/user/Model/User.php');
		$this->m = new place_Model_Place();
		$this->mCity = new place_Model_City();
		$this->mDistrict = new place_Model_District();
		$this->mVillage = new place_Model_Village();
		$this->mArticle = new article_Model_Service();
		$this->mCategory = new category_Model_Category();
		$this->mCategory->setTables('place');
		$this->mComment = new comment_Model_Service();
		$this->mVicinity = new place_Model_Vicinity();
		$this->mode = 'debug';
		parent::init();
	}
    
    public function importAnhAction()
    {
    	$fileArray = array (
//    		"religion" => APP_PATH. "/misc/data/20091210/Bien tap/Danh sach chua.csv", //OK
//    		//"hotel"  => APP_PATH. "/misc/data/hotel.csv",
			//"retaurant" => APP_PATH. "/misc/data/nha hang.csv.true", // OK
    		//"nature"  => APP_PATH. "/misc/data/cong vien.csv.true", // OK
//			//"embassy" => APP_PATH. "/misc/data/embassy.csv",
			"atm-bank" => APP_PATH. "/misc/data/20091210/Bien tap/atm-bank.csv.true", //OK
			//"handicraftVillages" => APP_PATH. "/misc/data/lang nghe.csv.true", // OK
    		//"museum" => APP_PATH. "/misc/data/bao tang.csv.true", // OK
//    		"shopping" => APP_PATH. "/misc/data/20091210/Bien tap/market.csv.true", // OK
    		//"taxi" => APP_PATH. "/misc/data/taxi.csv.true", // OK
//			"hospital" => APP_PATH. "/misc/data/20091210/Bien tap/Benh vien.csv", //OK
//			"beach" => APP_PATH. "/misc/data/bai bien.csv", // OK
//			"bar-cafe" => APP_PATH. "/misc/data/20091210/Bien tap/bar-cafe-hanoi.csv.true",//OK
//			"entertainment" => APP_PATH. "/misc/data/20091210/Bien tap/cinema.csv.true", // OK
//			"transportion" => APP_PATH. "/misc/data/20091210/Bien tap/Nha ga.csv", // OK
//			"travel-company" => APP_PATH. "/misc/data/20091210/Bien tap/Cong ty DL.csv", // chua OK
//			"sport-club" => APP_PATH. "/misc/data/caulacbothethao.csv.true", //OK
//			"ecological-travel" => APP_PATH. "/misc/data/du lich sinh thai.csv.true", // OK
//			"adtrative-area" => APP_PATH. "/misc/data/20091210/Bien tap/Co quan hanh chinh.csv", //OK
//			"karaoke" => APP_PATH. "/misc/data/20091210/Bien tap/karaoke.csv.true", //OK
//			"beautysalon" => APP_PATH. "/misc/data/20091210/Bien tap/beauty salon.csv.true", //OK
    		);
    	foreach ($fileArray as $type => $file)
    	{
    		$this->processFile($type,$file);
    	}
        die('***done***');
    }

    public function processFile($type,$file)
    {
        $stream = fopen($file, 'r+', false);
        fgets($stream);
        while ($line = fgets($stream))
        {
        	$data = $this->parseLine($type, $line, $file);
        	/*
        	$fileTrue = $file . '.true';
        	$streamTrue = fopen($fileTrue, 'a');
        	if((isset($data['city_id']) &&$data['city_id'] != 0) )
        	{
       			fwrite($streamTrue,$line);
//				fclose($streamTrue);
        	}
        	*/
        	$this->insertPlace($data); //TODO: to be uncommeted when data is correctly parsed
        }
        fclose($stream);
    }
    
    public function parseLine($type, $line, $file)
    {
    	if ($type == 'religion')
    		return $this->parseReligionLine($line, $file);
    	if($type == 'hotel')
    		return $this->parseHotelLine($line, $file);
    	if($type == 'nature')
    		return $this->parseNatureParkLine($line, $file);
    	if($type == 'retaurant')
    		return $this->parseRestaurantLine($line, $file);
    	if($type == 'embassy')
    		return $this->parseEmbassyLine($line, $file);
    	if($type == 'beach')
    		return $this->parseBeachLine($line, $file);
		if($type == 'atm-bank')
			return $this->parseATM_BankLine($line, $file);
		if($type == 'shopping')
			return $this->parseShopingLine($line, $file);
		if($type == 'handicraftVillages')
			return $this->parseHandicraftVillagesLine($line, $file);
		if($type == 'museum')
			return $this->parseMuseumExhibitionLine($line, $file);
		if($type == 'bar-cafe')
			return $this->parseBarCafeLine($line, $file);
		if($type == 'entertainment')
			return $this->parseEntertaimentPlaceLine($line, $file);
		if($type == 'taxi')
			return $this->parseTaxiLine($line, $file);
		if($type == 'hospital')
			return $this->parseHospitalLine($line, $file);
		if($type == 'transportion')
			return $this->parseTransportionLine($line, $file);
		if($type == 'travel-company')
			return $this->parseTravelCompanyLine($line, $file);
		if($type == 'sport-club')
			return $this->parseSportClubLine($line, $file);
		if($type == 'ecological-travel')
			return $this->parseEcologicalTravelLine($line, $file);
		if($type == 'adtrative-area')
			return $this->parseAdtrativeAreaLine($line, $file);
		if($type == 'karaoke')
			return $this->parseKaraokeLine($line, $file);
		if($type == 'beautysalon')
			return $this->parseBeautySalonLine($line, $file);
			
    }
    
    public function parseReligionLine($line, $file)
    {
    	$keys = array (
    		0 => "excelId",
    		1 => "name",
    		2 => "category",
    		3 => "other_name", 
    		4 => "address9", 
    		5 => "address8",
    		6 => "address7",
    		7 => "address6",
    		8 => "address5", 
    		9 => "village",
    		10 => "district",
    		11 => "city",
    		12 => "geo_characteristics",
    		13 => "main_event_dates",
    		14 => "desc",
    		15 => "area",
    		16 => "built_year",
    		17 => "ditich_year"																																																																																																																																																																																																																																																	
		);
		
		$mapping['category']['chua'] = 37;
		$mapping['category']['den'] = 37;
		$mapping['category']['nha tho'] = 38;
		
		//$mapping['city']['TP Hồ Chí Minh'] = 34;
		
		$rawData = explode("*", $line);
		//make it associative
		for ($i = 0; $i < count($keys); $i++ )
			$data[$keys[$i]] = trim($rawData[$i]);

		//additional db data 
		//type & rtype
		$data['rtype'] = 19;
		$category_name = strtolower(VN_unaccent(trim($data['category'])));
		if (array_key_exists($category_name, $mapping['category']))
		{
			$data['type'] = $mapping['category'][$category_name];
		}
		//poster_id
		$data['poster_id'] = 5; // TODO: Lien Mai: 3, Lien.Nguyen : 4, Chung: 5
		$data['language'] = 'vi';
		$data['status'] = 'published';
//		die_a($data);
		return $this->parseDbData($data,$file, $line);
		
    }

	//parse hotel line
	public function parseHotelLine($line, $file)
    {
    	$keys = array (
    		0 => "excelId",
    		1 => "name",
    		2 => "category",
//    		3 => "other_name", 
    		3 => "address9", 
    		4 => "address8",
    		5 => "address7",
    		6 => "address6",
    		7 => "address5", 
    		8 => "village",
    		9 => "district",
    		10 => "city",
    		11 => "rtype",
    		12 => "close_by",
    		13 => "desc",
    		14 => "area",
    		15 => "number_of_rooms",
    		16 => "number_of_available_rooms",
    		17 => "tiennghi",
    		18 => "type",
    		19 => "conference_room",
    		20 => "other_services",
    		21 => "fees",
    		22 => "payment_method",
    		23 => "check_in",
    		24 => "check_out",
    		25 => "phone",
    		26 => "fax",
    		27 => "contact_email",
    		28 => "website"																																																																																																																																																																																																																																																	
		);
		
		$mapping['category']['khach san'] = 13;
		$mapping['category']['nha khach'] = 12;
		$mapping['category']['resort'] = 15;
		$mapping['category']['resort and spa'] = 15;
		$mapping['category']['nha nghi'] = 12;
		$mapping['category']['khu du lich'] = 15;
		$mapping['category']['lang du lich'] = 15;
		$mapping['category']['khu du lich sinh thai'] = 15;
		$mapping['category']['biet thu'] = 88;
		$mapping['category']['khu biet thu'] = 88;
		$mapping['category']['nha tro'] = 88;
		$mapping['category']['khu nghi mat'] = 15;	
		$mapping['category']['khu nghi duong'] = 15;
		$mapping['category']['khu du lich nghi duong'] = 15;
		$mapping['category']['villa'] = 88;
		$mapping['category']['nha vuon'] = 88;
		$mapping['category']['lu quan'] = 88;
		
		//$mapping['city']['TP Hồ Chí Minh'] = 34;
		
		$rawData = explode("*", $line);
		//make it associative
		for ($i = 0; $i < count($keys); $i++ )
			$data[$keys[$i]] = trim($rawData[$i]);

		//additional db data 
    	$fee_currency = explode(' ',$data['fees']);
    	if(count($fee_currency) == 2)
    	{
    		$data['fee'] = $fee_currency['0'];
	    	$data['fee_currency'] = $fee_currency['1'];
    	}
    	if(count($fee_currency) == 3)
    	{
	    	$data['fee'] = $fee_currency['0'];
	    	$data['fee_currency'] = $fee_currency['3'];
    	}
		//type & rtype
		$category_name = strtolower(VN_unaccent(trim($data['category'])));
		if($category_name != 'khach san' && array_key_exists($category_name, $mapping['category']))
//		if (array_key_exists($category_name, $mapping['category']))
		{
			$data['type'] = $mapping['category'][$category_name];
		}
		$rtype = explode(' ', $data['rtype']);
		$data['rtype'] = 3;
		//poster_id
		$data['poster_id'] = 5; // TODO: Lien Mai: 3, Lien.Nguyen : 4, Chung: 5
		$data['language'] = 'vi';
		$data['status'] = 'published';
//		die_a($data);
		return $this->parseDbData($data,$file, $line);
		
//		echo "<pre>"; print_r($dbData); echo "</pre>";
		
    }
	
	//parse nature lineAncient Place
	public function parseNatureParkLine($line, $file)
    {
    	$keys = array (
    		0 => "excelId",
    		1 => "name",
    		2 => "category",
    		3 => "address9", 
    		4 => "address8",
    		5 => "address7",
    		6 => "address6",
    		7 => "address5", 
    		8 => "village",
    		9 => "district",
    		10 => "city",
    		11 => "phone",
    		12 => "fax",
    		13 => "contact_email",
    		14 => "gioi thieu",
    		15 => "hinh anh"																																																																																																																																																																																																																																																	
		);
		
		$mapping['category']['cong vien'] = 'null';

		//$mapping['city']['TP Hồ Chí Minh'] = 34;
		
		$rawData = explode("*", $line);
		//make it associative
		for ($i = 0; $i < count($keys); $i++ )
			$data[$keys[$i]] = trim($rawData[$i]);
		//additional db data 
		//type & rtype
		$data['rtype'] = 16;
		
		$category_name = strtolower(VN_unaccent(trim($data['category'])));
		if (array_key_exists($category_name, $mapping['category']))
		{
			$data['type'] = $mapping['category'][$category_name];
		}
		
		//poster_id
		$data['poster_id'] = 5; // TODO: Lien Mai: 3, Lien.Nguyen : 4, Chung: 5
		$data['language'] = 'vi';
		$data['status'] = 'published';
		return $this->parseDbData($data,$file, $line);
		
//		echo "<pre>"; print_r($dbData); echo "</pre>";
		
    }
    
    //parse eating line
    //OK
	public function parseRestaurantLine($line, $file)
    {
    	$keys = array (
    		0 => "excelId",
    		1 => "name",
    		2 => "category",
    		3 => "address9", 
    		4 => "address8",
    		5 => "address7",
    		6 => "address6",
    		7 => "address5", 
    		8 => "village",
    		9 => "district",
    		10 => "city",
    		11 => "phone",
    		12 => "fax",
    		13 => "contact_email",
    		14 => "desc",
    		15 => "vi tri",
    		16 => "food",
    		17 => "drink",
    		18 => "hinh thuc phuc vu",
    		19 => "eating style",
    		20 => "so cho",
    		21 => "gio phuc vu",
    		22 => "fee",
    		23 => "payment_method",
    		24 => "other",
		);
		
		$mapping['category']['nha hang'] = 'null';
		
		$rawData = explode("*", $line);
		//make it associative
		for ($i = 0; $i < count($keys); $i++ )
			$data[$keys[$i]] = trim($rawData[$i]);

		//additional db data 
		//type & rtype
		$data['rtype'] = 2;
		$category_name = strtolower(VN_unaccent(trim($data['category'])));
		if (array_key_exists($category_name, $mapping['category']))
		{
			$data['type'] = $mapping['category'][$category_name];
		}
		$data['desc'] = $data['desc'] . $data['vi tri'] . $data['food'] . $data['drink'] . $data['hinh thuc phuc vu'] . $data['eating style']
						. $data['so cho'] . $data['gio phuc vu'] . $data['other'];
		//poster_id
		$data['poster_id'] = 5; // TODO: Lien Mai: 3, Lien.Nguyen : 4, Chung: 5
		$data['language'] = 'vi';
		$data['status'] = 'published';
//		die_a($data);
		return $this->parseDbData($data,$file, $line);
    }
    
    //parse embassy lineAncient Place
	public function parseEmbassyLine($line, $file)
    {
    	$keys = array (
    		0 => "excelId",
    		1 => "name",
    		2 => "category",
    		3 => "address8",
    		4 => "address7",
    		5 => "address6",
    		6 => "address5", 
    		7 => "village",
    		8 => "district",
    		9 => "city",
    		10 => "phone",
    		11 => "fax",
    		12 => "website",
    		13 => "contact_email",
    		14 => "calendar_work",
    		15 => "ngay_quoc_khanh",
    		16 => "ngay_thiet_lap_quan_he",
    		17 => "ngay_dat_tru_so",																																																																																																																																																																																																																																																	
		);
		
		$mapping['category']['dai su quan'] = 23;
		$mapping['category']['to chuc quoc te'] = 80;
		$mapping['category']['van phong hop tac phat trien'] = 79;
		$mapping['category']['lanh su quan'] = 78;
        $mapping['category']['tong lanh su quan'] = 78;
        $mapping['category']['thuong vu dai su quan'] = 23;
        $mapping['category']['thuong vu tong lanh su quan'] = 78;
		
		//$mapping['city']['TP Hồ Chí Minh'] = 34;
		
		$rawData = explode("*", $line);
		//make it associative
		for ($i = 0; $i < count($keys); $i++ )
			$data[$keys[$i]] = trim($rawData[$i]);
		//additional db data 
		//type & rtype
		$data['rtype'] = 8;
		/*
		$category_name = strtolower(VN_unaccent(trim($data['category'])));
		if (array_key_exists($category_name, $mapping['category']))
		{
			$data['type'] = $mapping['category'][$category_name];
		}
		*/
		$data['desc'] = $data['calendar_work'] . $data['ngay_quoc_khanh'] . $data['ngay_thiet_lap_quan_he'] .
						$data['ngay_dat_tru_so'];
		//poster_id
		$data['poster_id'] = 5; // TODO: Lien Mai: 3, Lien.Nguyen : 4, Chung: 5
		$data['language'] = 'vi';
		$data['status'] = 'published';
//		die_a($data);
		return $this->parseDbData($data,$file, $line);
		
//		echo "<pre>"; print_r($dbData); echo "</pre>";
		
    }
    
     //parse beach line
	public function parseBeachLine($line, $file)
    {
    	$keys = array (
    		0 => "excelId",
    		1 => "name",
    		2 => "other_name", 
    		3 => "category",
    		4 => "address8",
    		5 => "address7",
    		6 => "address6",
    		7 => "address5", 
    		8 => "village",
    		9 => "district",
    		10 => "city",
    		11 => "desc",
    		12 => "notes",
		);
		
		$mapping['category']['bien'] = 'null';
		
		//$mapping['city']['TP Hồ Chí Minh'] = 34;
		
		$rawData = explode("*", $line);
		//make it associative
		for ($i = 0; $i < count($keys); $i++ )
			$data[$keys[$i]] = trim($rawData[$i]);

		//additional db data 
		//type & rtype
		$data['rtype'] = 17;
		/*
		$category_name = strtolower(VN_unaccent(trim($data['category'])));
		if (array_key_exists($category_name, $mapping['category']))
		{
			$data['type'] = $mapping['category'][$category_name];
		}
		*/
		$data['desc'] = $data['desc'] . $data['notes'];
		//poster_id
		$data['poster_id'] = 5; // TODO: Lien Mai: 3, Lien.Nguyen : 4, Chung: 5
		$data['language'] = 'vi';
		$data['status'] = 'published';
		return $this->parseDbData($data,$file, $line);
    }
    
     //parse atm-bank line 
     //OK
	public function parseATM_BankLine($line, $file)
    {
    	$keys = array (
    		0 => "excelId",
    		1 => "name",
    		2 => "address7",
    		3 => "address6",
    		4 => "address5",
    		5 => "village",
    		6 => "district",
    		7 => "city",
    		8 => "dia_diem",
    		9 => "time",
    		10 => "nguon",
		);
		
		//$mapping['category']['ngan hang'] = 12;
		
		$rawData = explode("*", $line);
		//make it associative
		for ($i = 0; $i < count($keys); $i++ )
			$data[$keys[$i]] = trim($rawData[$i]);

		//additional db data 
		$data['rtype'] = 59;
//		$category_name = strtolower(VN_unaccent(trim($data['category'])));
//		if (array_key_exists($category_name, $mapping['category']))
//		{
//			$data['type'] = $mapping['category'][$category_name];
//		}
		$data['desc'] = ' Diem chap nhan the: ' . $data['dia_diem'] . ', ' . ' Gio hoat dong' . ': ' . $data['time']. ' Nguon: ' . $data['nguon'];
		//poster_id
		$data['poster_id'] = 5; // TODO: Lien Mai: 3, Lien.Nguyen : 4, Chung: 5
		$data['language'] = 'vi';
		$data['status'] = 'published';
//		die_a($data);
		return $this->parseDbData($data,$file, $line);
    }
    
    //parse tradition lineAncient Place
	public function parseHandicraftVillagesLine($line, $file)
    {
    	$keys = array (
    		0 => "excelId",
    		1 => "name",
    		2 => "category",
//    		3 => "address8",
//    		4 => "address7",
//    		5 => "address6",
    		3 => "address5", 
    		4 => "village",
    		5 => "district",
    		6 => "city",
    		7 => "dac_diem_dia_ly",
    		8 => "dac_diem_dac_sac",
    		9 => "dac_diem_hinh_thanh",
    		10 => "other",
		);
		
		$rawData = explode("*", $line);
		//make it associative
		for ($i = 0; $i < count($keys); $i++ )
			$data[$keys[$i]] = trim($rawData[$i]);
//		die_a($data);
		//additional db data 
		//type & rtype
		$data['rtype'] = 15;
		/*
		$category_name = strtolower(VN_unaccent(trim($data['category'])));
		if (array_key_exists($category_name, $mapping['category']))
		{
			$data['type'] = $mapping['category'][$category_name];
		}
		*/
		$data['desc'] = 'Dc diem dac sac: ' . $data['dac_diem_dac_sac'] . 
						$data['dac_diem_hinh_thanh'] . $data['dac_diem_dia_ly'];
		//poster_id
		$data['poster_id'] = 5; // TODO: Lien Mai: 3, Lien.Nguyen : 4, Chung: 5
		$data['language'] = 'vi';
		$data['status'] = 'published';
//		die_a($data);
		return $this->parseDbData($data,$file, $line);
		
//		echo "<pre>"; print_r($dbData); echo "</pre>";
		
    }
    
    //parse shopping
    //OK
	public function parseShopingLine($line, $file)
    {
    	$keys = array (
    		0 => "excelId",
    		1 => "name",
    		//2 => "category",
    		2 => "address9",
    		3 => "address8",
    		4 => "address7",
    		5 => "address6",
    		6 => "address5", 
    		7 => "village",
    		8 => "district",
    		9 => "city",
    		10 => "phone",
    		11 => "fax",
    		12 => "contact_email",
    		13 => "website",
		);
		/*
		$mapping['category']['cua hang luu niem'] = 53;
		$mapping['category']['trung tam hoi cho'] = 44;
		*/
		$rawData = explode("*", $line);
		//make it associative
		for ($i = 0; $i < count($keys); $i++ )
			$data[$keys[$i]] = trim($rawData[$i]);
		//additional db data 
		//type & rtype
		$data['rtype'] = 5;
		/*
		$category_name = strtolower(VN_unaccent(trim($data['category'])));
		if (array_key_exists($category_name, $mapping['category']))
		{
			$data['type'] = $mapping['category'][$category_name];
		}
		*/
		$data['type'] = 54;
		//poster_id
		$data['poster_id'] = 5; // TODO: Lien Mai: 3, Lien.Nguyen : 4, Chung: 5
		$data['language'] = 'vi';
		$data['status'] = 'published';
//		die_a($data);
		return $this->parseDbData($data,$file, $line);
		
//		echo "<pre>"; print_r($dbData); echo "</pre>";
		
    }
    //OK
    public function parseBarCafeLine($line, $file)
    {
    	$keys = array (
    		0 => "excelId",
    		1 => "name",
    		2 => "category",
    		3 => "address9",
    		4 => "address8",
    		5 => "address7",
    		6 => "address6",
    		7 => "address5", 
    		8 => "village",
    		9 => "district",
    		10 => "city",
    		11 => "desc",
    		12 => "vitri",
    		13 => "drink",
    		14 => "siting_style",
    		15 => "opening_hours",
    		16 => "fee",
    		17 => "payment_method",
    		18 => "other",
    		19 => "phone",
    		20 => "fax",
    		21 => "contact_email",
    		22 => "website",
		);
		
		//$mapping['category']['cafe'] = 4;
		
		//$mapping['city']['TP Hồ Chí Minh'] = 34;
		
		$rawData = explode("*", $line);
		//make it associative
		for ($i = 0; $i < count($keys); $i++ )
			$data[$keys[$i]] = trim($rawData[$i]);
		//additional db data 
		$data['rtype'] = 4;
		/*
		$category_name = strtolower(VN_unaccent(trim($data['category'])));
		if (array_key_exists($category_name, $mapping['category']))
		{
			$data['type'] = $mapping['category'][$category_name];
		}
		*/
		$data['desc'] = $data['desc'] . ', ' . $data['vitri'] . ', ' . $data['drink'] . ', ' . $data['siting_style'] . ', ' . $data['other'];
		//poster_id
		$data['poster_id'] = 5; // TODO: Lien Mai: 3, Lien.Nguyen : 4, Chung: 5
		$data['language'] = 'vi';
		$data['status'] = 'published';
//		die_a($data);
		return $this->parseDbData($data,$file, $line);
    }
    
    public function parseEntertaimentPlaceLine($line, $file)
    {
    	$keys = array (
    		0 => "excelId",
    		1 => "name",
    		2 => "category",
    		3 => "address8",
    		4 => "address7",
    		5 => "address6",
    		6 => "address5", 
    		7 => "village",
    		8 => "district",
    		9 => "city",
    		10 => "dac_diem",
    		11 => "phone",
    		12 => "gia_ve",
    		13 => "website",
		);
		/*
		$mapping['category']['spa'] = 34;
		$mapping['category']['toc'] = 34;
		$mapping['category']['lam dep - massage'] = 34;
		$mapping['category']['the hinh - the duc tham my'] = 34;
		$mapping['category']['tiem lam toc'] = 34;
		$mapping['category']['nha hat - nha van hoa'] = 36;
		$mapping['category']['Cinema'] = 36;
		$mapping['category']['nha hat'] = 36;
		$mapping['category']['ca hue'] = 36;
		$mapping['category']['san khau - nha hat'] = 36;
		$mapping['category']['cau lac bo'] = 36;
		$mapping['category']['nha van hoa'] = 36;
		$mapping['category']['nha thieu nhi'] = 36;
		*/
		
		$rawData = explode("*", $line);
		//make it associative
		for ($i = 0; $i < count($keys); $i++ )
			$data[$keys[$i]] = trim($rawData[$i]);

		//additional db data 
		//type & rtype
		$data['rtype'] = 36;
		$data['desc'] = $data['dac_diem'] . ', ' . $data['gia_ve'];
		/*
		$category_name = strtolower(VN_unaccent(trim($data['category'])));
		if (array_key_exists($category_name, $mapping['category']))
		{
			$data['type'] = $mapping['category'][$category_name];
		}
		*/
		//poster_id
		$data['poster_id'] = 5; // TODO: Lien Mai: 3, Lien.Nguyen : 4, Chung: 5
		$data['language'] = 'vi';
		$data['status'] = 'published';
//		die_a($data);
		return $this->parseDbData($data,$file, $line);
		
    }
    
    public function parseTaxiLine($line, $file)
    {
    	$keys = array (
    		0 => "excelId",
    		1 => "name",
    		2 => "category",
    		3 => "address9", 
    		4 => "address8",
    		5 => "address7",
    		6 => "address6",
    		7 => "address5", 
    		8 => "village",
    		9 => "district",
    		10 => "city",
    		11 => "phone",
    		12 => "fax",
    		13 => "contact_email",
    		14 => "website",
    		15 => "fee",
		);

		$rawData = explode("*", $line);
		//make it associative
		for ($i = 0; $i < count($keys); $i++ )
			$data[$keys[$i]] = trim($rawData[$i]);

		//additional db data 
		//type & rtype
		$data['rtype'] = 20;
		/*
		$category_name = strtolower(VN_unaccent(trim($data['category'])));
		if (array_key_exists($category_name, $mapping['category']))
		{
			$data['type'] = $mapping['category'][$category_name];
		}
		*/
		//poster_id
		$data['poster_id'] = 5; // TODO: Lien Mai: 3, Lien.Nguyen : 4, Chung: 5
		$data['language'] = 'vi';
		$data['status'] = 'published';
//		die_a($data);
		return $this->parseDbData($data,$file, $line);
    }
    
    //OK
    public function parseHospitalLine($line, $file)
    {
    	$keys = array (
    		0 => "excelId",
    		1 => "name",
    		2 => "category",
    		3 => "address12",
    		4 => "address11",
    		5 => "address10",
    		6 => "address9", 
    		7 => "address8",
    		8 => "address7",
    		9 => "address6",
    		10 => "address5", 
    		11 => "village",
    		12 => "district",
    		13 => "city",
    		14 => "contact_email",
    		15 => "website",
    		16 => "phone",
    		17 => "desc",
		);

		$mapping['category']['benh vien tuyen huyen'] = 45;
		$mapping['category']['benh vien tuyen trung uong'] = 45;
		$mapping['category']['phong kham tu nhan'] = 51;
		$mapping['category']['tram xa'] = 46;
		$mapping['category']['phong kham da khoa khu vuc'] = 47;
		$mapping['category']['phong kham da khoa'] = 47;
		$mapping['category']['phong kham'] = 47;
		$mapping['category']['trung tam y te'] = 46;
		$mapping['category']['benh vien tuyen  huyen'] = 45;
		$mapping['category']['benh vien tuyen thanh pho'] = 45;
		$mapping['category']['benh vien da khoa'] = 45;
		$mapping['category']['benh vien'] = 45;
		$mapping['category']['benh vien cong'] = 45;
		$mapping['category']['nha khoa phong kham'] = 47;
		$mapping['category']['phong kham nha khoa'] = 47;
		
		$rawData = explode("*", $line);
		//make it associative
		for ($i = 0; $i < count($keys); $i++ )
			$data[$keys[$i]] = trim($rawData[$i]);

		//additional db data 
		//type & rtype
		$data['address9'] .= $data['address10'] . $data['address11'] . $data['address12'];
		$data['rtype'] = 11;
		$category_name = strtolower(VN_unaccent(trim($data['category'])));
		
		if (array_key_exists($category_name, $mapping['category']))
		{
			$data['type'] = $mapping['category'][$category_name];
		}
		//poster_id
		$data['poster_id'] = 59; // TODO: Lien Mai: 3, Lien.Nguyen : 4, Chung: 5, Thu Thuy vicky: 59
		$data['language'] = 'vi';
		$data['status'] = 'published';
		return $this->parseDbData($data,$file, $line);
    }
    
    //OK
     public function parseTransportionLine($line, $file)
    {
    	$keys = array (
    		0 => "excelId",
    		1 => "name",
    		2 => "category",
    		3 => "address9", 
    		4 => "address8",
    		5 => "address7",
    		6 => "address6",
    		7 => "address5", 
    		8 => "village",
    		9 => "district",
    		10 => "city",
    		11 => "phone",
    		12 => "fax",
    		13 => "website",
    		14 => "contact_email", 
		);
		$mapping['category'][' '] = 48;
		/*
		$mapping['category']['ga'] = 48;
		$mapping['category']['ben xe'] = 50;
		$mapping['category']['hang khong'] = 49;
		$mapping['category']['trung tam dieu hanh ben xe khach'] = 49;
		$mapping['category']['trung tam bao hanh xe'] = 49;
		$mapping['category']['ben tau'] = 50;
		$mapping['category']['cang hang khong'] = 48;
		$mapping['category']['ga tau'] = 48;
		$mapping['category']['tt bao duong'] = 49;
		$mapping['category']['ben tau'] = 48;
		$mapping['category']['trung ta, sua chua'] = 49;
		$mapping['category']['ga tau hoa'] = 48;
		$mapping['category']['san bay'] = 48;
		$mapping['category']['ben tau thuy'] = 48;
		$mapping['category']['hang hang khong'] = 48;
		$mapping['category']['nha ga'] = 48;
		$mapping['category']['duong hang khong'] = 48;
		$mapping['category']['san bay dich vu'] = 48;
		$mapping['category']['dan dung'] = 48;
		$mapping['category']['quan su va dan su'] = 48;
		$mapping['category']['dan su'] = 48;
		$mapping['category']['san bay quan su'] = 48;
		*/
		$rawData = explode("*", $line);
		//make it associative
		for ($i = 0; $i < count($keys); $i++ )
			$data[$keys[$i]] = trim($rawData[$i]);

		//additional db data 
		$data['rtype'] = 9;

		$category_name = strtolower(VN_unaccent(trim($data['category'])));
		
		if (array_key_exists($category_name, $mapping['category']))
		{
			$data['type'] = $mapping['category'][$category_name];
		}
		$data['type'] = 48;
		//poster_id
		$data['poster_id'] = 59; // TODO: Lien Mai: 3, Lien.Nguyen : 4, Chung: 5
		$data['language'] = 'vi';
		$data['status'] = 'published';
//		die_a($data);
		return $this->parseDbData($data,$file, $line);
    }
     //OK
     public function parseTravelCompanyLine($line, $file)
    {
    	$keys = array (
    		0 => "excelId",
    		1 => "name",
    		2 => "address9", 
    		3 => "address8",
    		4 => "address7",
    		5 => "address6",
    		6 => "address5", 
    		7 => "village",
    		8 => "district",
    		9 => "city",
    		10 => "phone",
    		11 => "fax",
    		12 => "contact_email",
    		13 => "website",
    		14 => "null",
		);

		$rawData = explode("*", $line);
		//make it associative
		for ($i = 0; $i < count($keys); $i++ )
			$data[$keys[$i]] = trim($rawData[$i]);

		//additional db data 
		//type & rtype
		$data['rtype'] = 10;
		/*
		$category_name = strtolower(VN_unaccent(trim($data['category'])));
		
		if (array_key_exists($category_name, $mapping['category']))
		{
			$data['type'] = $mapping['category'][$category_name];
		}
		*/
		
		//poster_id
		$data['poster_id'] = 5; // TODO: Lien Mai: 3, Lien.Nguyen : 4, Chung: 5
		$data['language'] = 'vi';
		$data['status'] = 'published';
//		die_a($data);
		return $this->parseDbData($data, $file, $line);
    }
     //OK
     public function parseSportClubLine($line, $file)
    {
    	$keys = array (
    		0 => "excelId",
    		1 => "name",
    		2 => "category",
    		3 => "address9", 
    		4 => "address8",
    		5 => "address7",
    		6 => "address6",
    		7 => "address5", 
    		8 => "village",
    		9 => "district",
    		10 => "city",
    		11 => "phone",
    		12 => "fax",
		);
		
		$mapping['category']['golf'] = 39;
		$mapping['category']['bi - a'] = 40;
		$mapping['category']['cau lac bo the hinh'] = 43;
		$mapping['category']['CLB tennis'] = 39;
		$mapping['category']['CLB the hinh tham my'] = 43;
		$mapping['category']['CLB boi loi'] = 42;
		$mapping['category']['CLB golf'] = 39;
		$mapping['category']['CLB vo thuat'] = 43;
		$mapping['category']['trung tam yoga'] = 43;
		$mapping['category']['san van dong'] = 40;
		$mapping['category']['CLB khieu vu'] = 43;
		$mapping['category']['cau long tennis'] = 45;
		$mapping['category']['be boi'] = 42;
		
		$rawData = explode("*", $line);
		//make it associative
		for ($i = 0; $i < count($keys); $i++ )
			$data[$keys[$i]] = trim($rawData[$i]);

		//additional db data 
		//type & rtype
		$data['rtype'] = 13;
		$category_name = strtolower(VN_unaccent(trim($data['category'])));
		
		if (array_key_exists($category_name, $mapping['category']))
		{
			$data['type'] = $mapping['category'][$category_name];
		}
		//poster_id
		$data['poster_id'] = 5; // TODO: Lien Mai: 3, Lien.Nguyen : 4, Chung: 5
		$data['language'] = 'vi';
		$data['status'] = 'published';
//		die_a($data);
		return $this->parseDbData($data,$file, $line);
    }
    
     public function parseMuseumExhibitionLine($line, $file)
    {
    	$keys = array (
    		0 => "excelId",
    		1 => "name",
    		2 => "address9", 
    		3 => "address8",
    		4 => "address7",
    		5 => "address6",
    		6 => "address5", 
    		7 => "village",
    		8 => "district",
    		9 => "city",
    		10 => "do_trung_bay",
    		11 => "desc",
    		12 => "opening_hours",
    		13 => "info",
    		14 => "phone",
    		15 => "fax",
    		16 => "contact_email",
    		17 => "website",
		);

		$rawData = explode("*", $line);
		//make it associative
		for ($i = 0; $i < count($keys); $i++ )
			$data[$keys[$i]] = trim($rawData[$i]);

		//additional db data 
		//type & rtype
		$data['desc'] .= $data['do_trung_bay'] . $data['info'];
		$data['rtype'] = 14;
		/*
		$category_name = strtolower(VN_unaccent(trim($data['category'])));
		
		if (array_key_exists($category_name, $mapping['category']))
		{
			$data['type'] = $mapping['category'][$category_name];
		}
		*/
		//poster_id
		$data['poster_id'] = 5; // TODO: Lien Mai: 3, Lien.Nguyen : 4, Chung: 5
		$data['language'] = 'vi';
		$data['status'] = 'published';
//		die_a($data);
		return $this->parseDbData($data,$file, $line);
    }
    
    public function parseEcologicalTravelLine($line, $file)
    {
    	$keys = array (
    		0 => "excelId",
    		1 => "name",
    		2 => "other_name",
    		3 => "category",
    		4 => "address8",
    		5 => "address7",
    		6 => "address6",
    		7 => "address5", 
    		8 => "village",
    		9 => "district",
    		10 => "city",
    		11 => "desc",
    		12 => "notes",
    		13 => "phone",
		);

		$rawData = explode("*", $line);
		//make it associative
		for ($i = 0; $i < count($keys); $i++ )
			$data[$keys[$i]] = trim($rawData[$i]);

		//additional db data 
		//type & rtype
		$data['rtype'] = 18;
		/*
		$category_name = strtolower(VN_unaccent(trim($data['category'])));
		if (array_key_exists($category_name, $mapping['category']))
		{
			$data['type'] = $mapping['category'][$category_name];
		}
		*/
		//poster_id
		$data['poster_id'] = 5; // TODO: Lien Mai: 3, Lien.Nguyen : 4, Chung: 5
		$data['language'] = 'vi';
		$data['status'] = 'published';
//		die_a($data);
		return $this->parseDbData($data,$file, $line);
    }
    
    //OK
    public function parseAdtrativeAreaLine($line, $file)
    {
    	$keys = array (
    		0 => "excelId",
    		1 => "name",
    		2 => "category",
    		3 => "address9", 
    		4 => "address8",
    		5 => "address7",
    		6 => "address6",
    		7 => "address5", 
    		8 => "village",
    		9 => "district",
    		10 => "city",
    		11 => "phone",
    		12 => "fax",
    		13 => "contact_email",
    		14 => "website",
		);

		$rawData = explode("*", $line);
		//make it associative
		for ($i = 0; $i < count($keys); $i++ )
			$data[$keys[$i]] = trim($rawData[$i]);

		//additional db data 
		$data['rtype'] = 7;
		/*
		$category_name = strtolower(VN_unaccent(trim($data['category'])));
		if (array_key_exists($category_name, $mapping['category']))
		{
			$data['type'] = $mapping['category'][$category_name];
		}
		*/
		//poster_id
		$data['poster_id'] = 5; // TODO: Lien Mai: 3, Lien.Nguyen : 4, Chung: 5
		$data['language'] = 'vi';
		$data['status'] = 'published';
//		die_a($data);
		return $this->parseDbData($data, $file, $line);
    }
    
     public function parseKaraokeLine($line, $file)
    {
    	$keys = array (
    		0 => "excelId",
    		1 => "name",
    		2 => "category",
    		3 => "address9", 
    		4 => "address8",
    		5 => "address7",
    		6 => "address6",
    		7 => "address5", 
    		8 => "village",
    		9 => "district",
    		10 => "city",
    		11 => "phone",
		);

		$rawData = explode("*", $line);
		//make it associative
		for ($i = 0; $i < count($keys); $i++ )
			$data[$keys[$i]] = trim($rawData[$i]);

		//additional db data 
		$data['rtype'] = 35;
		/*
		$category_name = strtolower(VN_unaccent(trim($data['category'])));
		if (array_key_exists($category_name, $mapping['category']))
		{
			$data['type'] = $mapping['category'][$category_name];
		}
		*/
		//poster_id
		$data['poster_id'] = 5; // TODO: Lien Mai: 3, Lien.Nguyen : 4, Chung: 5
		$data['language'] = 'vi';
		$data['status'] = 'published';
//		die_a($data);
		return $this->parseDbData($data, $file, $line);
    }
    
     public function parseBeautySalonLine($line, $file)
    {
    	$keys = array (
    		0 => "excelId",
    		1 => "name",
    		2 => "category",
    		3 => "address9", 
    		4 => "address8",
    		5 => "address7",
    		6 => "address6",
    		7 => "address5", 
    		8 => "village",
    		9 => "district",
    		10 => "city",
    		11 => "phone",
    		12 => "fax",
    		13 => "contact_email",
    		14 => "website",
		);

		$rawData = explode("*", $line);
		//make it associative
		for ($i = 0; $i < count($keys); $i++ )
			$data[$keys[$i]] = trim($rawData[$i]);

		//additional db data 
		$data['rtype'] = 34;
		/*
		$category_name = strtolower(VN_unaccent(trim($data['category'])));
		if (array_key_exists($category_name, $mapping['category']))
		{
			$data['type'] = $mapping['category'][$category_name];
		}
		*/
		//poster_id
		$data['poster_id'] = 5; // TODO: Lien Mai: 3, Lien.Nguyen : 4, Chung: 5
		$data['language'] = 'vi';
		$data['status'] = 'published';
//		die_a($data);
		return $this->parseDbData($data, $file, $line);
    }
    
    //parse the city, district,village name and turn them to city ids
    //$file could be pagoda, restaurants... for different file/fields formats
    //http://marcgrabanski.com/article/jquery-select-list-values
    
    public function parseDbData($data, $file, $line)
    {
    	$ret = $data;
    	//deal with city
    	$data['city'] = $this->unaccentAndStripCityNamePrefixes($data['city']);
    		
//		$fileFalse = $file . '.false';
//    	$streamFalse = fopen($fileFalse, 'a');
    	$ret['city_id'] = $this->getCityIdFromName($data['city'], $line );
		if ($ret['city_id'] == 0 ) //error
		{
			//write to $file. '.false';
       		//fwrite($streamFalse,$line);
		}

    	//deal with district & villlage
    	if (!empty($data['district']) && $ret['city_id'] > 0)
    	{
    		$data['district'] = $this->unaccentAndStripDistrictNamePrefixes($data['district']);
    		$ret['district_id'] = $this->getDistrictIdFromName($data['district'], $ret['city_id'], $line);

			if (!empty($data['village']) && $ret['district_id'] > 0 )
			{
	    		$data['village'] = $this->unaccentAndStripVillageNamePrefixes($data['village']);
				$ret['village_id'] = $this->getVillageIdFromName($data['village'], $ret['district_id'], $line);
			}
    	}
//		if(!isset($ret['village_id']) || (isset($ret['village_id']) && $ret['village_id'] == 0) 
//			|| !isset($ret['district_id']) || (isset($ret['district_id']) && $ret['district_id'] == 0))
//		{
//       		fwrite($streamFalse,$line);
//		}
    	
    	return $ret;
    }
    
    public function unaccentAndStripCityNamePrefixes($name)
    {
    	//remove words like thị trấn, thanh pho, Thanh Pho
    	$ret = strtolower(VN_unaccent_vowels($name));
    	
    	$ret = str_replace("tp", '', $ret);
    	$ret = str_replace("thanh pho", '', $ret);
    	$ret = trim($ret,' .,');
    	$ret = str_replace(" ", '%', $ret);
    	return $ret;
    }
    
    
    public function unaccentAndStripDistrictNamePrefixes($name)
    {
    	//remove words like thị trấn, thanh pho, Thanh Pho
    	$ret = preg_replace("/^Quận (.*)/", '$1', $name);
    	$ret = preg_replace("/^quận (.*)/", '$1', $ret);
//    	$ret = str_replace("quận", '', $name);
    	$ret = strtolower(trim((VN_unaccent_vowels($ret))));
    	
    	$ret = str_replace("thi tran ", '', $ret);
    	$ret = str_replace("thi xa ", '', $ret);
    	$ret = str_replace("tx ", '', $ret);
    	$ret = str_replace("tx.", '', $ret);
    	$ret = str_replace("tp ", '', $ret);
    	$ret = str_replace("tp. ", '', $ret);
    	$ret = str_replace("thanh pho ", '', $ret);
    	$ret = str_replace("huyen ", '', $ret);
    	$ret = str_replace("quan ", '', $ret);
    	$ret = str_replace("phuong ", '', $ret);
    	$ret = str_replace("q ", '', $ret);
    	$ret = str_replace(" h ", '', $ret);
    	$ret = str_replace("h ", '', $ret);
    	$ret = str_replace("h.", '', $ret);
    	$ret = str_replace("p ", '', $ret);
    	$ret = trim($ret,' .,');
    	$ret = str_replace(" ", '%', $ret);
    	return $ret;
    }

    public function unaccentAndStripVillageNamePrefixes($name)
    {
    	//remove words like thị trấn, thanh pho, Thanh Pho
    	$ret = preg_replace("/^Phường (.*)/", '$1', $name);
    	$ret = preg_replace("/^phường (.*)/", '$1', $ret);
//    	$ret = str_replace("quận", '', $name);
    	$ret = strtolower(trim(VN_unaccent_vowels($ret)));
    	
    	$ret = str_replace("xa ", '', $ret);
    	$ret = str_replace("phuong ", '', $ret);
    	$ret = str_replace("tt ", '', $ret);
    	$ret = str_replace("p ", '', $ret);
    	$ret = str_replace("p. ", '', $ret);
    	$ret = str_replace("p.", '', $ret);
    	$ret = str_replace("x. ", '', $ret);
    	$ret = str_replace("x ", '', $ret);
    	$ret = preg_replace("/^thi tran (.*)/", '$1', $ret);
    	$ret = preg_replace("/^tt (.*)/", '$1', $ret);
    	$ret = trim($ret,' .,');
    	$ret = str_replace(" ", '%', $ret);
    	return $ret;
    }  
    
    /*
     * Return city id or 0 if error
     */
    public function getCityIdFromName($processedCityName, $line)
    {
    	$sql = sprintf("SELECT * FROM cities WHERE city_name LIKE '%s'", "%" . $processedCityName . "%");
		$query = $this->db->query($sql);
    	$ret = $query->fetchAll();
			
    	if (count($ret) > 1)
    	{
			echo "<hr/>There is more than 1 matching city <br/>" . $line . "<br/>";
			return 0; // Error
    	}
    	else if (count($ret) == 0)
    	{
    		echo "<hr/>No matched city found<br/>" . $line . "<br/>";
    		return 0; // Error
    	}
    	else
    	{
    		if ($this->mode == 'debug')
    			echo $ret[0]['city_name'];
    		return $ret[0]['city_id'];
    	}
    }
    /*
    	See getCityIdFromName
    */
    public function getDistrictIdFromName($districtName, $cityId, $line)
    {
    	$pattern = "/(.*)(\d+)$/";
    	if (preg_match($pattern, $districtName))
    	    $sql = sprintf("SELECT * FROM districts WHERE city_id=%d AND district_name LIKE '%s'", $cityId, $districtName);
		else//    		die($districtName);
		{
			$districtName = str_replace(" ", '%', $districtName);
    		$sql = sprintf("SELECT * FROM districts WHERE city_id=%d AND district_name LIKE '%s'", $cityId, "%" . $districtName);
		}
		try{
			$query = $this->db->query($sql);
	    	$ret = $query->fetchAll();
		}
		catch(Exception $e)
		{
			return 0;
		}
    	
    	if (count($ret) > 1)
    	{
//			echo "<hr/>There is more than 1 matching districts <br/>" . $line . "<br/>";
			return 0; // Error
    	}
    	else if (count($ret) == 0)
    	{
//    		echo "<hr/>No matched districts found<br/>" . $line . "<br/>";
    		return 0; // Error
    	}
      		
    	else
    	{
//    		if ($this->mode == 'debug')
//    			echo $ret[0]['district_name'];
    		return $ret[0]['district_id'];
    	}
    }
    /* 
     * See getCityIdFromName
     * 
     */
    public function getVillageIdFromName($villageName, $districtId, $line)
    {
    	$pattern = "/(.*)(\d+)$/";
    	if (preg_match($pattern, $villageName))
    	    $sql = sprintf("SELECT * FROM villages WHERE district_id=%d AND village_name LIKE '%s'", $districtId, $villageName);
		else//    		die($districtName);
		{
			$villageName = str_replace(" ", '%', $villageName);
    		$sql = sprintf("SELECT * FROM villages WHERE district_id=%d AND village_name LIKE '%s'", $districtId, "%" . $villageName);
		}
		try
		{
			$query = $this->db->query($sql);
	    	$ret = $query->fetchAll();
		}
		catch(Exception $e)
		{
			return 0;
		}
		
    	if (count($ret) > 1)
    	{
//			echo "<hr/>There is more than 1 matching vilages <br/>" . $line . "<br/>";
			return 0; // Error
    	}
    	else if (count($ret) == 0)
    	{
//    		echo "<hr/>No matched vilages found<br/>" . $line . "<br/>";
    		return 0; // Error
    	}
      		      		
    	else
    	{
    		if ($this->mode == 'debug')
    			echo $ret[0]['village_name'];
    		return $ret[0]['village_id'];
    	}
    }
    
    public function insertPlace($data)
    {
    	//now we have data that contains the necessary keys for place
    	//insert article first
	    $db = $this->db;
        $db->beginTransaction();
        try 
        {
        	$data['article_language'] = $data['language']; 
        	$data['article_title'] = $data['name'];
        	$data['article_poster_id'] = $data['poster_id'];
        	$data['article_module'] = 'place';
        	$data['article_status'] = isset($data['status']) ? $data['status'] : 
        			Zend_Registry::get('configuration')->general->defaultNodeStatus->place;
        	$data['status'] = $data['article_status'];
        	if (isset($data['desc']))
        		$data['article_body'] = $data['desc'];
        	else 
        		$data['article_body'] = '';
			$data['article_poster_id'] = $data['poster_id']; 
//	    	die_a($data);
			       	
        	//insert article_title
            if (!$this->mArticle->insertRaw($data,false))
            {
            	$this->view->errorMessage .= t(503);
            }
            $article_id = $db->lastInsertId();
            //insert place
			if($article_id != 0)
            {
            	$data['article_id'] = $article_id;
            	$data['country_id'] = 84;
//            	die_a($data);
	            try
		    	{
	    			$placeId = $this->m->insertAllRaw($data,false); //TODO: fix in Model
		    	}
		    	catch (Exception $e) 
		    	{
		    		$this->mArticle->deleteByPrimary(array($article_id), false);
		    	    $this->view->errorMessage .= $e->getMessage() . "<br/>" . t(723);
		    	    die($e->getMessage());
		    	}
            }
            else
            {
            	die($this->view->errorMessage);
            }
             
            $db->commit();
        }
        catch (Exception $e)
        {
            $db->rollBack();
            $this->view->errorMessage .= $e->getMessage() . "<br/>". t(69);
            die($e->getMessage());
        }
        if (empty($this->view->errorMessage)) //SUCCESSFUL
        {
        	/*
	    	$url = $this->view->hvnUrl(array('module'=>'place', 'action'=>'edit'));
			$this->_helper->redirector->gotoUrl($url . '?id='.$placeId.'&j=1'); //TODO
        	return;
			*/
        }
		else
		{
			die($this->view->errorMessage);
		}    
    }
}
?>
